//
//  HNMyOrderController.m
//  JHFBaseProject
//
//  Created by 朱传正 on 2017/1/5.
//  Copyright © 2017年 好牛. All rights reserved.
//

#import "HNMyOrderController.h"
#import "HNOrderShoppingCell.h"
#import "HNOrderConsultCell.h"
#import "OrderProductListController.h"

@interface HNMyOrderController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,assign) NSInteger currentHeadTag;

@property (nonatomic,strong) NSMutableArray *dataSource;

@property (nonatomic,strong) UIScrollView *contentScrollView;

@property (nonatomic,strong) UILabel *topTitle;

@property (nonatomic,strong) UIButton *topBackBtn;

@property (nonatomic,strong) UIButton *consultBtn;
@property (nonatomic,strong) UIButton *shoppingBtn;

//咨询订单
@property (strong, nonatomic) UIView *consultHeadView;

@property (nonatomic,assign)NSInteger consultState;

//选项卡形态控制
@property (nonatomic,strong)UILabel *consultLabel0;
@property (nonatomic,strong)UIView *consultLineView0;
@property (nonatomic,strong)UILabel *consultLabel1;
@property (nonatomic,strong)UIView *consultLineView1;
@property (nonatomic,strong)UILabel *consultLabel2;
@property (nonatomic,strong)UIView *consultLineView2;


//药品订单
@property (strong, nonatomic) UIView *shoppingHeadView;

@property (nonatomic,assign)NSInteger shoppingState;

//选项卡形态控制
@property (nonatomic,strong)UILabel *choiceLabel0;
@property (nonatomic,strong)UIView *choiceLineView0;
@property (nonatomic,strong)UILabel *choiceLabel1;
@property (nonatomic,strong)UIView *choiceLineView1;
@property (nonatomic,strong)UILabel *choiceLabel2;
@property (nonatomic,strong)UIView *choiceLineView2;
@property (nonatomic,strong)UILabel *choiceLabel3;
@property (nonatomic,strong)UIView *choiceLineView3;



@property (strong, nonatomic) UITableView *orderListTableView;




@end

@implementation HNMyOrderController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}

-(void)drawView{
  
    _currentHeadTag = 10;
    _dataSource = [NSMutableArray array];
    _orderType = orderType_Consult;
//    _dataSource = [NSMutableArray array];
    [self createTopView];
    [self.consultBtn setSelected:YES];
    [self.consultBtn setSelected:NO];
    
    [self setConsultHeadSection];
    [self setShoppingHeadSection];
    [_consultHeadView setHidden:NO];
    [_shoppingHeadView setHidden:YES];
    
    [self setOrderListView];
    
}

-(void)initData{
    
}

#pragma mark - 创建导航栏
-(void)createTopView{
    UIView *topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreen_Width, 64)];
    topView.backgroundColor = RGB(249, 249, 249);
    [self.view addSubview:topView];
    
    UILabel *lineView = [[UILabel alloc]initWithFrame:CGRectMake(0, 63.5, kScreen_Width, 0.5)];
    lineView.backgroundColor = [UIColor grayColor];
    [topView addSubview:lineView];
    
    //添加点击按钮---咨询订单按钮
    _consultBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_consultBtn setTitle:@"咨询订单" forState:UIControlStateNormal];
    [_consultBtn setFont:[UIFont systemFontOfSize:15]];
    [_consultBtn setBackgroundColor:RGB(249, 249, 249)];
    [_consultBtn setTitleColor:RGBJ(44) forState:UIControlStateNormal];
    _consultBtn.tag = 10;
    [_consultBtn setBackgroundImage:nil forState:UIControlStateNormal];
    [_consultBtn setBackgroundImage:nil forState:UIControlStateSelected];
    _consultBtn.frame = CGRectMake(kScreen_Width/2 - 100, 25, 100, 30);
    [_consultBtn addTarget:self action:@selector(changeOrderStyle:) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:_consultBtn];
    //添加点击按钮---药品订单按钮
    _shoppingBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_shoppingBtn setTitle:@"药品订单" forState:UIControlStateNormal];
    [_shoppingBtn setFont:[UIFont systemFontOfSize:15]];
        [_shoppingBtn setBackgroundImage:nil forState:UIControlStateNormal];
    [_shoppingBtn setBackgroundImage:nil forState:UIControlStateSelected];
     [_shoppingBtn setBackgroundColor:RGB(249, 249, 249)];
    [_shoppingBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    _shoppingBtn.tag = 11;
    _shoppingBtn.frame = CGRectMake(kScreen_CenterX/2 + 100, 25, 100, 30);
    [_shoppingBtn addTarget:self action:@selector(changeOrderStyle:) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:_shoppingBtn];
    
    _topBackBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [_topBackBtn setFont:[UIFont systemFontOfSize:15]];
    [_topBackBtn setBackgroundImage:[UIImage imageNamed:@"xiangyou.png"] forState:UIControlStateNormal];
    [_topBackBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _topBackBtn.frame = CGRectMake(8,28,24,24);
    [_topBackBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:_topBackBtn];
    
}

-(void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)changeOrderStyle:(UIButton *)btn{
    
    //10 咨询订单  11 药品订单
    NSInteger tag = btn.tag;
    if (tag == 10) {
        if (_currentHeadTag == tag) {
            return;
        }
        _currentHeadTag = tag;
         UIButton *myButton = (UIButton *)[self.view viewWithTag:(11)];
        myButton.selected = NO;
        
         _orderType = orderType_Consult;
        [_consultBtn setTitleColor:RGBJ(44) forState:UIControlStateNormal];
        [_shoppingBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];

        [_consultHeadView setHidden:NO];

        [_shoppingHeadView setHidden:YES];
        
        [self setConsultStateColor:0];
        
    }else if (tag == 11){
        if (_currentHeadTag == tag) {
            return;
        }
        _currentHeadTag = tag;
         _orderType = orderType_Shopping;
        [_consultBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [_shoppingBtn setTitleColor:RGBJ(44) forState:UIControlStateNormal];
        [_consultHeadView setHidden:YES];
        [_shoppingHeadView setHidden:NO];
        
         [self setStateColor:0];
    }
    
    
}

#pragma mark - 药品订单页面创建
-(void)setConsultHeadSection{
    _consultHeadView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, kScreen_Width, 40)];
    _consultHeadView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_consultHeadView];
    
    UILabel *lineView = [[UILabel alloc]initWithFrame:CGRectMake(0, 39.5, kScreen_Width, 0.5)];
    lineView.backgroundColor = [UIColor grayColor];
    [_consultHeadView addSubview:lineView];
    
    NSArray *nameArray = [NSArray arrayWithObjects:@"全部",@"待付款",@"已付款",nil];
    
    for (int i = 0; i < nameArray.count; i++) {
        UIView *itemView = [[UIView alloc]initWithFrame:CGRectMake( kScreen_Width/nameArray.count * i, 0, kScreen_Width/nameArray.count,_consultHeadView.frame.size.height)];
        [self.consultHeadView addSubview:itemView];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, itemView.frame.size.width, itemView.frame.size.height - 20)];
        label.tag = 100 + i;
        label.text = nameArray[i];
        label.textColor = RGBJ(50);
        label.textAlignment =  NSTextAlignmentCenter ;
        label.font = [UIFont systemFontOfSize:14];
        [itemView addSubview:label];
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(5, itemView.frame.size.height - 1, itemView.frame.size.width-10,1)];
        lineView.tag = 500 + i;
        [lineView setHidden:YES];
        lineView.backgroundColor = RGB(253, 108, 110);
        [itemView addSubview:lineView];
        switch (i) {
            case 0:
                self.consultLabel0 = label;
                self.consultLineView0 = lineView;
                break;
            case 1:
                self.consultLabel1 = label;
                self.consultLineView1 = lineView;
                break;
            case 2:
                self.consultLabel2 = label;
                self.consultLineView2 = lineView;
                break;
                
                
            default:
                break;
        }
        //添加点击按钮 - 切换
        UIButton *clickBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [clickBtn setTitle:@"" forState:UIControlStateNormal];
        [clickBtn setBackgroundColor:RGBA(255, 255, 255, 0)];
        [clickBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        clickBtn.frame = CGRectMake(0, 0, itemView.frame.size.width, itemView.frame.size.height);//大小和位置
        clickBtn.tag = 500 + i;
        [clickBtn addTarget:self action:@selector(clickConsultInAction:) forControlEvents:UIControlEventTouchUpInside];//button被按下又抬起后发生的事件
        [itemView addSubview:clickBtn];
    }
//    [self setConsultStateColor:0];
}


//推荐、闲置、寄卖、代购选择后执行的方法
-(void)clickConsultInAction:(UIButton *)btn{
    [self setConsultStateColor:btn.tag - 500];
    
}

//选择按钮状态变换
-(void)setConsultStateColor:(NSInteger)num{
    _consultState = num;
    switch (num) {
        case 0://全部
            self.consultLabel0.textColor = RGB(253, 118, 110);
            [self.consultLineView0 setHidden:NO];
            self.consultLabel1.textColor = RGBJ(77);
            [self.consultLineView1 setHidden:YES];
            self.consultLabel2.textColor = RGBJ(77);
            [self.consultLineView2 setHidden:YES];
            
            
            [self getOrderData];//获取数据
            break;
        case 1://代付款
            self.consultLabel0.textColor = RGBJ(77);
            [self.consultLineView0 setHidden:YES];
            self.consultLabel1.textColor = RGB(253, 118, 110);
            [self.consultLineView1 setHidden:NO];
            self.consultLabel2.textColor = RGBJ(77);
            [self.consultLineView2 setHidden:YES];
            
            
            [self getOrderData];//获取数据
            break;
        case 2://已付款
            self.consultLabel0.textColor = RGBJ(77);
            [self.consultLineView0 setHidden:YES];
            self.consultLabel1.textColor = RGBJ(77);
            [self.consultLineView1 setHidden:YES];
            self.consultLabel2.textColor = RGB(253, 118, 110);
            [self.consultLineView2 setHidden:NO];
            
            
            [self getOrderData];//获取数据
            break;
            
        default:
            break;
    }
    
}


#pragma mark - 药品订单页面创建
-(void)setShoppingHeadSection{
    _shoppingHeadView = [[UIView alloc]initWithFrame:CGRectMake(0, 64, kScreen_Width, 40)];
    _shoppingHeadView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_shoppingHeadView];
    
    UILabel *lineView = [[UILabel alloc]initWithFrame:CGRectMake(0, 39.5, kScreen_Width, 0.5)];
    lineView.backgroundColor = [UIColor grayColor];
    [_shoppingHeadView addSubview:lineView];
    
    NSArray *nameArray = [NSArray arrayWithObjects:@"全部",@"待付款",@"已付款",@"已结算",nil];
    
    for (int i = 0; i < nameArray.count; i++) {
        UIView *itemView = [[UIView alloc]initWithFrame:CGRectMake( kScreen_Width/nameArray.count * i, 0, kScreen_Width/nameArray.count,_shoppingHeadView.frame.size.height)];
        [self.shoppingHeadView addSubview:itemView];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, itemView.frame.size.width, itemView.frame.size.height - 20)];
        label.tag = 100 + i;
        label.text = nameArray[i];
        label.textColor = RGBJ(50);
        label.textAlignment =  NSTextAlignmentCenter ;
        label.font = [UIFont systemFontOfSize:14];
        [itemView addSubview:label];
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(5, itemView.frame.size.height - 1, itemView.frame.size.width-10,1)];
        lineView.tag = 500 + i;
        [lineView setHidden:YES];
        lineView.backgroundColor = RGB(253, 108, 110);
        [itemView addSubview:lineView];
        switch (i) {
            case 0:
                self.choiceLabel0 = label;
                self.choiceLineView0 = lineView;
                break;
            case 1:
                self.choiceLabel1 = label;
                self.choiceLineView1 = lineView;
                break;
            case 2:
                self.choiceLabel2 = label;
                self.choiceLineView2 = lineView;
                break;
            case 3:
                self.choiceLabel3 = label;
                self.choiceLineView3 = lineView;
                break;
    
                
            default:
                break;
        }
        //添加点击按钮 - 切换
        UIButton *clickBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [clickBtn setTitle:@"" forState:UIControlStateNormal];
        [clickBtn setBackgroundColor:RGBA(255, 255, 255, 0)];
        [clickBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        clickBtn.frame = CGRectMake(0, 0, itemView.frame.size.width, itemView.frame.size.height);//大小和位置
        clickBtn.tag = 500 + i;
        [clickBtn addTarget:self action:@selector(clickInAction:) forControlEvents:UIControlEventTouchUpInside];//button被按下又抬起后发生的事件
        [itemView addSubview:clickBtn];
    }
     [self setStateColor:0];
}


//推荐、闲置、寄卖、代购选择后执行的方法
-(void)clickInAction:(UIButton *)btn{
    [self setStateColor:btn.tag - 500];
    
}

//选择按钮状态变换
-(void)setStateColor:(NSInteger)num{
    _shoppingState = num;
    switch (num) {
        case 0://推荐
            self.choiceLabel0.textColor = RGB(253, 118, 110);
            [self.choiceLineView0 setHidden:NO];
            self.choiceLabel1.textColor = RGBJ(77);
            [self.choiceLineView1 setHidden:YES];
            self.choiceLabel2.textColor = RGBJ(77);
            [self.choiceLineView2 setHidden:YES];
            self.choiceLabel3.textColor = RGBJ(77);
            [self.choiceLineView3 setHidden:YES];
            
            
            [self getOrderData];//获取数据
            break;
        case 1://关注
            self.choiceLabel0.textColor = RGBJ(77);
            [self.choiceLineView0 setHidden:YES];
            self.choiceLabel1.textColor = RGB(253, 118, 110);
            [self.choiceLineView1 setHidden:NO];
            self.choiceLabel2.textColor = RGBJ(77);
            [self.choiceLineView2 setHidden:YES];
            self.choiceLabel3.textColor = RGBJ(77);
            [self.choiceLineView3 setHidden:YES];
    
            
             [self getOrderData];//获取数据
            break;
        case 2://闲置
            self.choiceLabel0.textColor = RGBJ(77);
            [self.choiceLineView0 setHidden:YES];
            self.choiceLabel1.textColor = RGBJ(77);
            [self.choiceLineView1 setHidden:YES];
            self.choiceLabel2.textColor = RGB(253, 118, 110);
            [self.choiceLineView2 setHidden:NO];
            self.choiceLabel3.textColor = RGBJ(77);
            [self.choiceLineView3 setHidden:YES];
    
            
            [self getOrderData];//获取数据
            break;
        case 3://闲置
            self.choiceLabel0.textColor = RGBJ(77);
            [self.choiceLineView0 setHidden:YES];
            self.choiceLabel1.textColor = RGBJ(77);
            [self.choiceLineView1 setHidden:YES];
            self.choiceLabel2.textColor = RGBJ(77);
            [self.choiceLineView2 setHidden:YES];
            self.choiceLabel3.textColor = RGB(253, 118, 110);
            [self.choiceLineView3 setHidden:NO];
            
            [self getOrderData];//获取数据
            break;

        default:
            break;
    }
    
}

#pragma mark - 订单列表创建
-(void)setOrderListView{
    _orderListTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64 + 40, kScreen_Width, kScreen_Height - 64 - 40)];
    [self.view addSubview:_orderListTableView];
    
    [_orderListTableView setBackgroundColor:RGB(236, 240, 241)];
    _orderListTableView.delegate = self;
    _orderListTableView.dataSource = self;
    
    [_orderListTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
    //上拉刷新
    MJRefreshGifHeader *header = [[MJRefreshGifHeader alloc]init];
    [header setRefreshingBlock:^(void){
//        _page = 1;
        [self getOrderData];
    }];
    _orderListTableView.mj_header = header;
    //下拉刷新
//    _orderListTableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^(void){
////        _page ++;
//        //        [_tableView reloadData];
//    }];
    
    
}

#pragma -mark TableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return _dataSource.count;
    
  
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([_orderType isEqualToString:orderType_Consult]) {
      return 60;
    }else{
      return 192;
    }
  
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *orderDic = _dataSource[indexPath.row];
    if ([_orderType isEqualToString:orderType_Consult]) {
        static NSString *CellIdentifier = @"HNOrderConsultCell";
        HNOrderConsultCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]firstObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }

        cell.cellTime.text = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"createTime"]];
        NSString *cellName = [NSString stringWithFormat:@"%@元图文咨询",[orderDic objectForKey:@"money"]];
        cell.cellName.text = cellName;
        CGFloat money = [[NSString stringWithFormat:@"%@",[orderDic objectForKey:@"money"]] floatValue];
        if (money > 0) {
             cell.cellName.text = cellName;
             [cell changeNameSize:cellName andState:YES];
        }else{
             cell.cellName.text =@"免费图文咨询";
        }
        cell.cellDes.text = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"buyerNickname"]];
        [cell.cellImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",url_Base,[orderDic objectForKey:@"buyerPhoto"]]] placeholderImage:[UIImage imageNamed:@"icon_019_cover.png"] ];
        NSInteger btnState = [[NSString stringWithFormat:@"%@",[orderDic objectForKey:@"status"]] integerValue];
        if (money == 0) {
            btnState = 1;
        }
        [cell changeState:btnState];
      
        
        return cell;

    }else{
        static NSString *CellIdentifier = @"HNOrderShoppingCell";
        
        HNOrderShoppingCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil]firstObject];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        
        NSArray *goodsArr = [NSArray arrayWithArray:[orderDic objectForKey:@"goods"]];
        if (_dataSource.count > 0) {
          
            if (goodsArr.count > 1) {
                [cell.cellImageRight setHidden:NO];
                
            }
            
            if(goodsArr.count == 0){
                [cell.cellImage setImage:[UIImage imageNamed:@"shopping.png"]];
              
                cell.cellname.text = @"药品订单";
            }else{
                NSDictionary * dict = [NSDictionary dictionaryWithDictionary:goodsArr[0]];
                NSString *imageStr = [NSString stringWithFormat:@"%@",[dict objectForKey:@"goodsImg"]];
                if ([AppConfig isStrNull:imageStr]) {
                    [cell.cellImage setImage:[UIImage imageNamed:@"shopping.png"]];
                }else{
                    [cell.cellImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",url_Base,imageStr]] placeholderImage:[UIImage imageNamed:@"shopping.png"]];
                }
                
                cell.cellname.text = [NSString stringWithFormat:@"%@",[dict objectForKey:@"goodsName"]];
            }
            
           
            cell.cellDes.text = [NSString stringWithFormat:@"所属药店：安徽益丰大药房"];
            NSInteger state = [[NSString stringWithFormat:@"%@",[orderDic objectForKey:@"status"]] integerValue];
            [cell changeState:state];
            
         
            
          
            NSString *money = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"money"]];
            cell.cellPrice.text = [NSString stringWithFormat:@"¥%@",money];
            cell.cellScore.text = [NSString stringWithFormat:@"%.0f",[money floatValue] * 100];
     
            cell.cellTime.text = [NSString stringWithFormat:@"%@",[orderDic objectForKey:@"createTime"]];
            
            
        }else{
            UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,60,kScreen_Width,43)];
            nameLabel.numberOfLines = 1;
            nameLabel.clipsToBounds = YES;
            nameLabel.layer.cornerRadius = 4;
            nameLabel.textAlignment = NSTextAlignmentCenter;
            nameLabel.font = [UIFont systemFontOfSize:15];
            nameLabel.backgroundColor = RGB(85, 206, 84);
            nameLabel.textColor = [UIColor whiteColor];
            nameLabel.text = @"暂无订单数据";
            cell.accessoryView = nameLabel;
        }
        
        return cell;

    }
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *orderDic = _dataSource[indexPath.row];
    NSArray *goodsArr = [NSArray arrayWithArray:[orderDic objectForKey:@"goods"]];
    if (goodsArr.count>1) {
        OrderProductListController * proList = [[OrderProductListController alloc]init];
        [proList setDataSource:goodsArr];
        [self.navigationController pushViewController:proList animated:YES];
    }
    
    
    
}

#pragma mark - 获取初始数据

-(void)getOrderData{
//    [self showHudInView:self.view hint:nil];
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObjectsAndKeys:static_sessionId,@"sessionId",nil];
    
    NSString *status = nil;
    if ([_orderType isEqualToString: orderType_Consult]) {
        status = [NSString stringWithFormat:@"%ld",_consultState-1];
    }else if([_orderType isEqualToString: orderType_Shopping]){
        status = [NSString stringWithFormat:@"%ld",_shoppingState - 1];
        [param setObject:@"0" forKey:@"type"];
        [param setObject:[EMClient sharedClient].currentUsername forKey:@"sellerUsername"];
    }
    
    if (_consultState > 0 || _shoppingState > 0) {
        [param setObject:status forKey:@"status"];
    }
   
    NSLog(@"param = %@",param);
    
    NSString *orderUrl = nil;
    if ([_orderType isEqualToString: orderType_Consult]) {
        orderUrl = url_order_mySell;
    }else if([_orderType isEqualToString: orderType_Shopping]){
      orderUrl = url_order_sesrch;
    }
    
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager manager] initWithBaseURL:[NSURL URLWithString:url_Base]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:orderUrl parameters:param progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSError * error;
        NSDictionary * data=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:&error];
        [self hideHud];
        if (error) {
            NSLog(@"====error1:%@",error);
            [self showHint:@"获取订单列表失败"];
            NSLog(@"==dict:%@",data);
            return;
        }
        NSLog(@"==dict:%@",data);
        
        NSString * result = [NSString stringWithFormat:@"%@",[data objectForKey:@"result"]];
        if ([result isEqualToString:@"1"]) {
            [self.dataSource removeAllObjects];
            NSArray * obj = [NSArray arrayWithArray:[data objectForKey:@"obj"]];
            NSLog(@"------obj = %@",obj);
            
            
            if (obj.count >0) {
                for (int i = 0; i < obj.count; i ++) {
                    NSLog(@"%@",obj[i]);
                    [self.dataSource addObject:obj[i]];
                }
                
                NSLog(@"===self.docterListSource = %@",self.dataSource);
            }
            
            [self.orderListTableView reloadData];
            [self.orderListTableView.mj_header endRefreshing];
            [self.orderListTableView.mj_footer endRefreshing];
            
            
        }else{
            NSString * info = [NSString stringWithFormat:@"%@",[data objectForKey:@"msg"]];
          
            [self.orderListTableView.mj_header endRefreshing];
            [self.orderListTableView.mj_footer endRefreshing];
            if ([info isEqualToString:msg_InvalidLoginInformation]) {
                
                [AppConfig removeUserInfo];
                
                [[EMClient sharedClient] logout:YES];
                [[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@NO];
                
                HNLoginViewController *loginVC = [[HNLoginViewController alloc]init];
                
                [self.navigationController pushViewController:loginVC animated:YES];
            }
            [self showHint:info];
            
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull  error) {
        NSLog(@"====error:%@",error);
        [self hideHud];
        [self showHint:@"获取订单列表失败"];
        [self.orderListTableView.mj_header endRefreshing];
        [self.orderListTableView.mj_footer endRefreshing];
    }];
    

    
    
    
 
}

@end
